package com.upu173.music.global;

import com.upu173.music.model.PlayList;

import java.util.ArrayList;
import java.util.List;

public class PlayerData{

    /**播放列表*/
    public static List<PlayList> playList = new ArrayList<>();

    /**当前播放的位置*/
    public static int position = -1;

    /**临时播放不放播放列表 position = -1时取这个值*/
    public static PlayList playSong;

    public static PlayList getCurrentPlaySong(){
        PlayList song = null;
        if(position == -1){
            return playSong;
        }else{
            if(playList.size() > position){
                song = playList.get(position);
            }
            return song;
        }

    }

    public static void setCurrentPlaySong(PlayList song){
        playSong = song;
        position = -1;
        for(int i =0;i<playList.size();i++){
            if(playList.get(i).getPath().equals(song.getPath())){
                position = i;
                break;
            }
        }
    }

    public static void setCurrentPlaySong(int positionNew){
        position = positionNew;
        playSong = null;
    }

    public static PlayList getNextPlaySong(){

        if(position == -1){
            if(playList.size() > 0){
                return playList.get(0);
            }
        }else {
            if(playList.size() > position + 2){
                return playList.get(position+1);
            }
        }
        return null;
    }
}
